﻿using B.S.BasicData.Api.Read.Application.Command;
using B.S.BasicData.Api.Read.Application.Command.Menu;
using B.S.BasicData.Api.Read.DTO;
using B.S.BasicData.ErrorCode;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace B.S.BasicData.Api.Read.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class MenuController : ControllerBase
    {
        private readonly IMediator mediator;

        public MenuController(IMediator mediator)
        {
            this.mediator = mediator;
        }
        /// <summary>
        /// 查询菜单信息
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        [Authorize]
        public Task<ApiPaging<MenuDTO>> GetMenu([FromQuery]GetMenuCommand request)
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 查询父级id为0的菜单名称
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        [Authorize]
        public Task<ApiResult<List<MenuDTO>>> GetParentMenu([FromQuery] GetParentMenuCommand request )
        {
            return mediator.Send(request);

        }
        /// <summary>
        /// 查询菜单下有没有子集
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        [Authorize]
        public Task<ApiResult<List<MenuDTO>>> GetMenuZi([FromQuery] GetMenuZiCommand request )
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 查询菜单的树形信息
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        [Authorize]
        public Task<ApiResult<List<TreeMenuDTO>>> GetTreeMenu([FromQuery] GetTreeMenuCommand request)
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 根据角色id查询菜单的信息（id）
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        [Authorize]
        public Task<ApiResult<List<int>>> GetBufenMenu([FromQuery] GetBuFenMenuCommand request)
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 根据角色id查询菜单的信息
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        [Authorize]
        public Task<ApiResult<List<UserRoleMenuDTO>>> GetRoleMenu([FromQuery] GetUserRoleMenuCommand request)
        {
            return mediator.Send(request);
        }
    }
}
